import dayjs from "dayjs";
import clipboard from 'clipboard'
import {message} from "ant-design-vue";
import {useUserStore} from '@/stores'

export const copy = (text) => {
  clipboard.copy(text);
  message.success('复制成功')
}
export const formattedDate = (timestamp) => {
  return dayjs(timestamp).format('YYYY-MM-DD HH:mm:ss');
}
// 判断是否登录
export const isLogin = (isAuth=false) => {
  const { token, loginToggle } = useUserStore()
  if (isAuth && !token) {
    loginToggle(true)
  }
  return !!token;
}
export const  splitArr = (arr) => { //arr是你要分割的数组，num是以几个为一组
  let newArr = [] //首先创建一个新的空数组。用来存放分割好的数组
  for (let i = 0; i < arr.length;) { //注意：这里与for循环不太一样的是，没有i++
    newArr.push(arr.slice(i, i += 5));
  }
  return newArr
}